#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/2/17 14:09
# @Author  : 新猿异码
# @Site    : https://gitee.com/chshao/autotest
# @CSDN    : https://blog.csdn.net/m0_37576542?type=blog
# @File    : api.py
# @Desc    : Android原生API
# @Software: PyCharm


class UiObjectApi(object):
    mode = "ui2"

    @staticmethod
    def click(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "click", [], ui2_expect_return
        return "ui_object_method_call", "click", [], ui1_expect_return

    @staticmethod
    def long_click(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "longClick", [], ui2_expect_return
        return "ui_object_method_call", "longClick", [], ui1_expect_return

    @staticmethod
    def click_wait_new_window(ui1_expect_return=None, ui2_expect_return=None):
        return "ui_object_method_call", "clickAndWaitForNewWindow", [], ui1_expect_return

    @staticmethod
    def drag(end_x: int, end_y: int, steps: int = 5, ui1_expect_return=None, ui2_expect_return=None):
        args = [{"k": "int", "v": end_x}, {"k": "int", "v": end_y}, {"k": "int", "v": steps}]
        return "ui_object_method_call", "dragTo", args, ui1_expect_return

    @staticmethod
    def swipe_up(steps, ui1_expect_return=None, ui2_expect_return=None):
        return "ui_object_method_call", "swipeUp", [{"k": "int", "v": steps}], ui1_expect_return

    @staticmethod
    def swipe_down(steps, ui1_expect_return=None, ui2_expect_return=None):
        return "ui_object_method_call", "swipeDown", [{"k": "int", "v": steps}], ui1_expect_return

    @staticmethod
    def swipe_left(steps, ui1_expect_return=None, ui2_expect_return=None):
        return "ui_object_method_call", "swipeLeft", [{"k": "int", "v": steps}], ui1_expect_return

    @staticmethod
    def swipe_right(steps, ui1_expect_return=None, ui2_expect_return=None):
        return "ui_object_method_call", "swipeRight", [{"k": "int", "v": steps}], ui1_expect_return

    @staticmethod
    def get_text():
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "getText", []
        return "ui_object_method_call", "getText", []

    @staticmethod
    def get_class_name():
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "getClassName", []
        return "ui_object_method_call", "getClassName", []

    @staticmethod
    def get_description():
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "getContentDescription", []
        return "ui_object_method_call", "getContentDescription", []

    @staticmethod
    def set_text(text, ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "setText", [{"k": "string", "v": text}], ui2_expect_return
        return "ui_object_method_call", "setText", [{"k": "string", "v": text}], ui1_expect_return

    @staticmethod
    def clear_text(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "clear", [], ui2_expect_return
        return "ui_object_method_call", "clearTextField", [], ui1_expect_return

    @staticmethod
    def is_selected(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isSelected", [], ui2_expect_return
        return "ui_object_method_call", "isSelected", [], ui1_expect_return

    @staticmethod
    def is_checkable(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isCheckable", [], ui2_expect_return
        return "ui_object_method_call", "isCheckable", [], ui1_expect_return

    @staticmethod
    def is_enabled(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isEnabled", [], ui2_expect_return
        return "ui_object_method_call", "isEnabled", [], ui1_expect_return

    @staticmethod
    def is_clickable(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isClickable", [], ui2_expect_return
        return "ui_object_method_call", "isClickable", [], ui1_expect_return

    @staticmethod
    def is_focused(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isFocused", [], ui2_expect_return
        return "ui_object_method_call", "isFocused", [], ui1_expect_return

    @staticmethod
    def is_scrollable(ui1_expect_return=None, ui2_expect_return=None):
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "isScrollable", [], ui2_expect_return
        return "ui_object_method_call", "isScrollable", [], ui1_expect_return

    @staticmethod
    def get_package_name():
        return "ui_object_method_call", "getPackageName", []

    @staticmethod
    def get_visible_bounds():
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "getVisibleBounds", []
        return "ui_object_method_call", "getVisibleBounds", []

    @staticmethod
    def get_bounds():
        return "ui_object_method_call", "getBounds", []

    @staticmethod
    def wait_for_exists(timeout, ui1_expect_return=None):
        return "ui_object_method_call", "waitForExists", [{"k": "long", "v": timeout}], ui1_expect_return

    @staticmethod
    def wait_until_gone(timeout, ui1_expect_return=None):
        return "ui_object_method_call", "waitUntilGone", [{"k": "long", "v": timeout}], ui1_expect_return

    @staticmethod
    def exists(ui1_expect_return=None):
        return "ui_object_method_call", "exists", [], ui1_expect_return

    @staticmethod
    def pinch_out(percent, steps, ui1_expect_return=None, ui2_expect_return=None):
        args = [{"k": "int", "v": percent}, {"k": "int", "v": steps}]
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "pinchOpen", args, ui2_expect_return
        return "ui_object_method_call", "pinchOut", args, ui1_expect_return

    @staticmethod
    def pinch_in(percent, steps, ui1_expect_return=None, ui2_expect_return=None):
        args = [{"k": "int", "v": percent}, {"k": "int", "v": steps}]
        if UiObjectApi.mode == "ui2":
            return "ui_object2_method_call", "pinchClose", args, ui2_expect_return
        return "ui_object_method_call", "pinchIn", args, ui1_expect_return
